@extends('admin.public')

@section('content')
    <div class="col-md-12">
        <form data-validate="parsley" method="post">
            <input type="hidden" name="chunk" value="{{ $chunk->id }}">
            {!! csrf_field() !!}
            <section class="panel panel-default">
                <header class="panel-heading">
                    {{ $chunk->name }}{{ $frame['title'] }}
                    <a href="{{ route('admin.fragment.fragment') }}" class="btn btn-xs btn-default pull-right">碎片列表</a>
                </header>
                <div class="panel-body">
                    <p class="text-muted">当前模块共有 <span class="text-info">{{ $infoNum['num'] }}</span> 条信息,其中最新信息 <span
                                class="text-info">{{ $infoNum['is_new'] }}</span>
                        条,热门信息 <span class="text-info">{{ $infoNum['is_hot'] }}</span> 条,推荐信息 <span
                                class="text-info">{{ $infoNum['is_push'] }}</span> 条!</p>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-6">
                            <label>碎片名称</label>
                            <input type="text" class="form-control parsley-validated" data-required="true" name="name"
                                   placeholder="请填写碎片名称">
                        </div>
                        <div class="col-sm-6">
                            <label>碎片标签</label>
                            <div class="input-group m-b">
                                <span class="input-group-addon">{{ '{' }}{ $fragment['</span>
                                <input type="text" class="form-control parsley-validated" data-required="true"
                                       placeholder="请填写碎片标签"
                                       name="path">
                                <span class="input-group-addon">'] }}</span>
                            </div>
                        </div>
                    </div>
                    <div class="form-group pull-in clearfix">
                        <div class="col-sm-4">
                            <label>碎片信息数量</label>
                            <input type="number" class="form-control parsley-validated" name="num" min="1" max="30"
                                   placeholder="请填写碎片信息数量" data-required="true">
                        </div>
                        <div class="col-sm-4">
                            <label>
                                排序方式
                                <small class="text-small">(默认为时间排序)</small>
                            </label>
                            <select name="type" class="form-control m-b">
                                <option value="1">设置排序</option>
                                <option value="2">访问量排序</option>
                            </select>
                        </div>
                        <div class="col-sm-4">
                            <label>碎片分类</label>
                            <div class="clearfix"></div>
                            <input type="hidden" name="sort" value="">
                            <select style="width:100%" multiple class="chosen-select srcsort">
                                @if( !empty($sorts) )
                                    @foreach( $sorts as $sortlv1 )
                                        <option value="{{ $sortlv1['id'] }}" selected>{{ $sortlv1['name'] }}</option>
                                        @if( !empty($sortlv1['children']) )
                                            @foreach( $sortlv1['children'] as $sortlv2 )
                                                <option style="text-indent: 20px"
                                                        value="{{ $sortlv2['id'] }}" selected>{{ $sortlv2['name'] }}</option>
                                                @if( !empty($sortlv2['children']) )
                                                    @foreach( $sortlv2['children'] as $sortlv3 )
                                                        <option style="text-indent: 40px" value="{{ $sortlv3['id'] }}" selected>
                                                            {{ $sortlv3['name'] }}</option>
                                                        @if( !empty($sortlv3['children']) )
                                                            @foreach( $sortlv3['children'] as $sortlv4 )
                                                                <option style="text-indent: 60px"
                                                                        value="{{ $sortlv4['id'] }}" selected>
                                                                    {{ $sortlv4['name'] }}</option>
                                                                @if( !empty($sortlv4['children']) )
                                                                    @foreach( $sortlv4['children'] as $sortlv5 )
                                                                        <option style="text-indent: 80px"
                                                                                value="{{ $sortlv5['id'] }}" selected>
                                                                            {{ $sortlv5['name'] }}</option>
                                                                    @endforeach
                                                                @endif
                                                            @endforeach
                                                        @endif
                                                    @endforeach
                                                @endif
                                            @endforeach
                                        @endif
                                    @endforeach
                                @endif
                            </select>
                        </div>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="status" checked
                                   class="parsley-validated"><i></i> 勾选此项,即开启此信息碎片
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_new"
                                   class="parsley-validated"><i></i> 勾选此项,即引用<span
                                    class="text-info">{{ $chunk->name }}</span>中的最新信息
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_push"
                                   class="parsley-validated"><i></i> 勾选此项,即引用<span
                                    class="text-info">{{ $chunk->name }}</span>中的推荐信息
                        </label>
                    </div>
                    <div class="checkbox i-checks">
                        <label>
                            <input type="checkbox" name="is_hot"
                                   class="parsley-validated"><i></i> 勾选此项,即引用<span
                                    class="text-info">{{ $chunk->name }}</span>中的热门信息
                        </label>
                    </div>
                </div>
                <footer class="panel-footer text-right bg-light lter">
                    <button type="submit" class="btn btn-success btn-s-xs gatherInfo">保存</button>
                </footer>
            </section>
        </form>
    </div>
@endsection

@section('css')
    <link rel="stylesheet" href="/public/theme/js/chosen/chosen.css" type="text/css"/>
@endsection

@section('js')
    <!-- parsley -->
    <script src="/public/theme/js/parsley/parsley.min.js"></script>
    <script src="/public/theme/js/parsley/parsley.extend.js"></script>

    <!-- Chosen -->
    <script src="/public/theme/js/chosen/chosen.jquery.min.js"></script>

    <script>
        $('.gatherInfo').click(function () {
            var need = '';
            $('a.search-choice-close').each(function () {
                var order = $(this).attr('data-option-array-index');
                var id = $('.srcsort').find('option:eq(' + order + ')').val();
                need += id + ',';
            })
            $('input[name="sort"]').val(need);
        });
    </script>
@endsection